
public class MyCP{
    public static void main(String[] args) throws IOException {
        java.lang.String file = "E:/zuoye9/src/shi.txt";
        String s =dataInputStream(file);//导入十进制txt文件
        FileOutputStream fps = new FileOutputStream("D:/zuoye9/src/er.txt");//将十进制转为二进制并保存为txt文件
        fps.write(s.getBytes());
        fps.close();
    }
    public static String dataInputStream(String file) throws IOException  //十进制转二进制
    {
        File file2 = new File(file);
        DataInputStream dls = new DataInputStream(new FileInputStream(file2));
        StringBuilder byData = new StringBuilder();
        byte b = 0;
        for(int i=0;i<file2.length();i++) //返回二进制的无符号整数
        {
            b = dls.readByte();//按字节读取
            String str = Integer.toBinaryString(b);
            if(str.length() == 1) {
                str = "0"+str;
            }
            byData.append(str.toUpperCase());
        }
        return byData.toString();
    }

    private static class IOException extends Exception {
    }
}